from functools import wraps
import logging


def logged(level, name=None, msg=None):
    def decorate(func):
        logname = name if name else func.__module__
        log = logging.getLogger(logname)
        logmsg = msg if msg else func.__name__

        @wraps(func)
        def wrapper(*args, **kw):
            log.log(level, logmsg)
            return func(*args, **kw)

        return wrapper

    return decorate


# example use
@logged(logging.DEBUG)
def add(x, y):
    return x + y


@logged(logging.CRITICAL, 'example')
def spam():
    print('Spam!')

if __name__ == '__main__':
    add(1,2)
    spam()